<%--
  Created by IntelliJ IDEA.
  User: zuxia
  Date: 2018/7/18
  Time: 12:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="../css/amazeui.min.css" />
    <link rel="stylesheet" href="../css/admin.css" />
    <link rel="stylesheet" href="../css/layui.css" />
    <link rel="stylesheet" href="../css/tanc.css" />


</head>

<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">订单管理</strong><small></small></div>

        <div class="am-u-sm-12 am-u-md-3">

        </div>
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-input-group am-input-group-sm">
                <input type="text" id="sousuo" class="am-form-field" placeholder="请输入订单号">
                <span class="am-input-group-btn">
            				<button class="am-btn am-btn-default" id="sousuobt" type="button">搜索</button>
          				</span>
            </div>
        </div>

    </div>

    <hr>

    <div class="am-g">
    </div>
    <div class="am-g">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-id">ID</th>
                        <th class="table-title">订单号</th>
                        <th class="table-author am-hide-sm-only">用户</th>
                        <th>桌号</th>
                        <th>人数</th>
                        <th class="table-author am-hide-sm-only">支付方式</th>
                        <th class="table-author am-hide-sm-only">订单状态</th>
                        <th class="table-date am-hide-sm-only">下单时间</th>
                        <th class="table-author am-hide-sm-only">备注</th>
                        <th class="table-set">操作</th>

                    </tr>
                    </thead>
                    <tbody id="table_tbody">
                    </tbody>
                </table>
                <hr>
            </form>
        </div>
    </div>
</div>
<!--弹出层时背景层DIV-->
<%--<div id="fade" class="black_overlay"></div>--%>
<%--<div id="MyDiv" class="white_content">--%>
    <%--<div style="text-align: right; cursor: default; height: 40px;">--%>
        <%--<span style="font-size: 16px;" onclick="CloseDiv('MyDiv','fade')">关闭</span>--%>
    <%--</div>--%>
    <%--<iframe id="deta" src="details.jsp" name="right" frameborder="0" scrolling="no"  width="100%" height="525px"></iframe>--%>
<%--</div>--%>
</body>

<script type="text/javascript" src="../js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="../js/tanc.js"></script>
<script type="text/javascript" src="../myplugs/js/plugs.js"></script>
<script type="text/javascript" src="../js/Popup.js"></script>

<script type="text/javascript" src="../js/jquery-1.4.1.js"></script>
<script type="text/javascript">
    //添加ajax分页
    $().ready(function() {
        //执行一次
        loaddata("","","");

        //搜索单击事件
        $("#sousuobt").click(function(){
            var keyword = $("#sousuo").val();
            //console.log(keyword);
            // 加载数据
            loaddata(keyword,"","");
        });
        // //详情按钮单击事件
        // $("#showorder").live("click",function(){
        //     var orderid=$(this).parent().parent().prevAll().last().text();
        //     console.log(orderid+"111");
        //     window.location.href="/fullboy/skipvalue.action?skipvalue="+orderid.trim();
        // });
        //删除按钮单击事件
        $("#deleteorder").live("click",function(){
            var orderid=$(this).parent().parent().prevAll().last().text();
            deleteorder(orderid);
            loaddata("","","");
        });

        $(".prev").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算上一页的页码
            var pageNo = $(".current_num").text();
            pageNo = parseInt(pageNo);
            if(pageNo == undefined || pageNo <= 1){
                pageNo = 1;
            }else{
                pageNo = pageNo -1;
            }
            // 加载数据
            loaddata(keyword, pageNo,"");
        });

        $(".next").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算下一页的页码
            var pageNo = $(".current_num").text();
            pageNo = parseInt(pageNo);
            var totalNo = $(".total_num").text();
            totalNo = parseInt(totalNo);
            if(pageNo == undefined){
                pageNo = 1;
            }else if(pageNo >= totalNo){
                pageNo =totalNo;
            }else{
                pageNo = pageNo + 1;
            }
            // 加载数据
            loaddata(keyword, pageNo,"");
        });

        $(".first").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算下一页的页码
            var pageNo = 1;
            // 加载数据
            loaddata(keyword, pageNo,"");
        });

        $(".last").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算下一页的页码
            var pageNo = $(".total_num").text();
            if(pageNo == undefined){
                pageNo = 1;
            }
            // 加载数据
            loaddata(keyword, pageNo,"");
        });

    });

    //删除事件
    function deleteorder(orderid) {
        $.ajax({
            url:"/fullboy/deleteorder.action",
            data:{"orderid":orderid},
            type: "POST",
            cache: false,
        });
    }
    //ajax加载数据方法
    function loaddata(keyword,pageno,pagesize) {
        $("#table_tbody").empty();
        $.ajax({
            url:"/fullboy/queryorder.action",
            //querydetailsorderid
            data:{"keyword":keyword,"pageno":pageno,"pagesize":pagesize},
            type: "POST",
            cache: false,
            dataType: "json",
            success:function(data){
                console.log(data);
                if(data.success){
                    var orderlist=data.data.list;
                    for(var i=0;i<orderlist.length;i++){
                        var orderlistobj=orderlist[i][0];
                        var userlistobj=orderlist[i][1];
                        $("#table_tbody").append("<tr>"+
                        "<td>"+orderlistobj.orderId+"</td>"+
                        "<td>"+orderlistobj.orderNo+"</td>"+
                        "<td>"+userlistobj.uName+"</td>"+
                        "<td>"+orderlistobj.tableNo+"</td>"+
                        "<td>"+orderlistobj.pNum+"</td>"+
                        "<td>"+orderlistobj.payType+"</td>"+
                        "<td class='am-hide-sm-only'>"+
                        "<a href='#'>"+orderlistobj.struts+"</a>"+
                        "</td>"+
                        "<td class='am-hide-sm-only'>"+orderlistobj.createTime+"</td>"+
                        "<td>"+orderlistobj.remark+"</td>"+
                        "<td>"+
                        //"<div class='am-btn-toolbar'>"+
                        "<div class='am-btn-group am-btn-group-xs'>"+
                        "<button id='showorder' class='am-btn am-btn-default am-btn-xs am-text-secondary '>"+
                        "<a href='#' onclick=\"ShowDivOrder('MyDiv','fade','"+orderlistobj.orderNo+"')\">查看</a>"+
                        "</button>"+
                        "<button id='deleteorder' class='am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only '>删除</button>"+
                        "</div>"+
                        //"</div>"+
                        "</td>"+
                        "</tr>");
                    }

                    $("#table_tbody").append("<tr style='border-bottom:1px solid #AAAAAA;height: 50px;text-align:center;'><td colspan='11'><div id='page_div'><span class='current_num'>" +
                        data.data.pageNo+"</span>/<span class='total_num'>"+data.data.pageCount+"</span>页   每页"+data.data.pageSize+"条  共"+
                        data.data.totalNumber+"条数据 "+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='prev'>上一页</a>"+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='next'>下一页</a>"+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='first'>首页</a> "+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='last'>尾页</a></div></td></tr>");
                }else{
                   $("#table_tbody").append("<tr><td colspan='11' style='color:#2530ff'>"+data.errorMessage+"</td></tr>");
                }
            }
        });
    }


</script>
</html>

